<template>
  <div class="reports">
    <el-breadcrumb separator-class="el-icon-arrow-right">
      <el-breadcrumb-item :to="{ path: '/home' }">首页</el-breadcrumb-item>
      <el-breadcrumb-item>数据统计</el-breadcrumb-item>
      <el-breadcrumb-item>数据报表</el-breadcrumb-item>
    </el-breadcrumb>
    <el-card>
      <div id="myChart" :style="{width: '100%', height: '550px'}"></div>
    </el-card>
  </div>
</template>

<script>
import _ from "lodash";
export default {
  name: "reports",
  data() {
    return {};
  },
  methods: {
    drawLine() {
      let myChart = this.$echarts.init(document.getElementById("myChart"));
      this.$http.get("reports/type/1").then((res) => {
        if (res.data.meta.status !== 200) {
          return this.$emssage.error("数据加载失败");
        }
        let options = {
          title: {
            text: "用户来源",
          },
          tooltip: {
            trigger: "axis",
            axisPointer: {
              type: "cross",
              label: {
                backgroundColor: "#E9EEF3",
              },
            },
          },
          grid: {
            left: "3%",
            right: "4%",
            bottom: "3%",
            containLabel: true,
          },
          xAxis: [
            {
              boundaryGap: false,
            },
          ],
          yAxis: [
            {
              type: "value",
            },
          ],
        };
        const chartdata = _.merge(options, res.data.data);
        myChart.setOption(chartdata);
      });
    },
  },
  mounted() {
    this.drawLine();
  },
};
</script>

<style scoped>
.el-breadcrumb {
  margin-bottom: 20px;
}
</style>
